<template>
    <div>
      <h2>员工登录页面</h2>
      员工姓名: <input type="text" v-model="username">
      密码: <input type="password" v-model="password">
      <button @click="sub">登录</button>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data(){
          return{
            username:'',
            password:'',
          }
        },
        methods:{
          sub(){
            // 1 模拟form表单
            let formdata=new FormData();

            // 2 将数据添加到表单中
            formdata.append('username',this.username);
            formdata.append('password',this.password);

            // 3 将表单发送给后端
            this.axios({
              url:'http://127.0.0.1:8000/app01/login/',
              method:'post',
              data:formdata,
            }).then(res=>{
              if(res.data.code==1000){
                this.$router.push('/staff')
              }else{
                alert(res.data.msg)
              }
            })

          }
        }

    }
</script>

<style scoped>

</style>
